//
//  MacroDefinition.h
//  MyNewProject
//
//  Created by sun on 2018/12/2.
//  Copyright © 2018 sun. All rights reserved.
//

#ifndef MacroDefinition_h
#define MacroDefinition_h


#endif /* MacroDefinition_h */

/**
 *  Application相关
 */
#pragma mark --- Application相关

#define APPLICATION         [UIApplication sharedApplication]
#define APPDLE              (AppDelegate*)[APPLICATION delegate]
#define SKKeyWindow          [UIApplication sharedApplication].keyWindow


/**
 *  判断当前的iPhone设备/系统版本
 */
#pragma mark --- 判断当前的iPhone设备/系统版本

//判断是否为iPhone
//#define IS_IPHONE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
#define IS_IPHONE ([[[UIDevice currentDevice] model] isEqualToString:@"iPhone"])

//判断是否为iPad
//#define IS_IPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
#define IS_IPAD ([[[UIDevice currentDevice] model] isEqualToString:@"iPad"])

//判断是否为ipod
#define IS_IPOD ([[[UIDevice currentDevice] model] isEqualToString:@"iPod touch"])

#define UI_IS_RETINA ([[UIScreen mainScreen] scale] >= 2.0)

// 系统版本号（string）
#define DEVICE_OS_VERSION       [[UIDevice currentDevice] systemVersion]
// 系统版本号（float）
#define DEVICE_OS_VERSION_VALUE [DEVICE_OS_VERSION floatValue]
//判断 iOS 8 或更高的系统版本
#define IOS_VERSION_8_OR_LATER (([[[UIDevice currentDevice] systemVersion] floatValue] >=8.0)? (YES):(NO))

//粗体
#define BoldFont(fontsize)       [UIFont fontWithName:@"Helvetica-Bold" size:fontsize]
//标准
#define LightFont(fontsize)       [UIFont fontWithName:@"Helvetica-Light" size:fontsize]

// app版本号
#define DEVICE_APP_VERSION      (NSString *)[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"]
// app Build版本号
#define DEVICE_APP_BUILD        (NSString *)[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"]


//获取当前系统语言
#define SKCurrentLanguage ([[NSLocale preferredLanguages] objectAtIndex:0])
//检测是否是竖屏状态
#define IsPortrait ([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationPortrait || [UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationPortraitUpsideDown)


//判断是不是真机
#if TARGET_OS_IPHONE
//iPhone Device
#endif

//判断是不是模拟器
#if TARGET_IPHONE_SIMULATOR
//iPhone Simulator
#endif

//是否在ARC环境下
#if __has_feature(objc_arc)
//compiling with ARC
#else
//compiling without ARC
#endif

/**
 *  屏幕宽度与高度
 */
#pragma mark --- 屏幕宽度与高度
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_8_0  // 当前Xcode支持iOS8及以上

#define SCREEN_WIDTH ([[UIScreen mainScreen] respondsToSelector:@selector(nativeBounds)]?[UIScreen mainScreen].nativeBounds.size.width/[UIScreen mainScreen].nativeScale:[UIScreen mainScreen].bounds.size.width)
#define SCREENH_HEIGHT ([[UIScreen mainScreen] respondsToSelector:@selector(nativeBounds)]?[UIScreen mainScreen].nativeBounds.size.height/[UIScreen mainScreen].nativeScale:[UIScreen mainScreen].bounds.size.height)
#define SCREEN_SIZE ([[UIScreen mainScreen] respondsToSelector:@selector(nativeBounds)]?CGSizeMake([UIScreen mainScreen].nativeBounds.size.width/[UIScreen mainScreen].nativeScale,[UIScreen mainScreen].nativeBounds.size.height/[UIScreen mainScreen].nativeScale):[UIScreen mainScreen].bounds.size)
#else
#define SCREEN_WIDTH [UIScreen mainScreen].bounds.size.width
#define SCREENH_HEIGHT [UIScreen mainScreen].bounds.size.height
#define SCREEN_SIZE [UIScreen mainScreen].bounds.size
#endif



///** 针对iPhoneX 高度作出的约束规范 */
//#define SKRealHeight              (long)(SCREENH_HEIGHT > 736 ? 736 : SCREENH_HEIGHT)
//
///** 相对4.0寸屏幕宽的自动布局 */
//#define SKRealWidth5(value)       (long)((value)/320.0f * [UIScreen mainScreen].bounds.size.width)
//
///** 相对4.0寸屏幕高的比例进行屏幕适配 */
//#define SKRealHeight5(value)      (long)((value)/568.0f * SKRealHeight)
//
///** 相对4.7寸屏幕宽的比例进行屏幕适配 */
//#define SKRealWidth6(value)       (long)((value)/375.0f * [UIScreen mainScreen].bounds.size.width)
//
///** 相对4.7寸屏幕高的比例进行屏幕适配 */
//#define SKRealHeight6(value)      (long)((value)/667.0f * SKRealHeight)
//
///** 相对5.5寸屏幕宽的比例进行屏幕适配 */
//#define SKRealWidth6P(value)      (long)((value)/414.0f * [UIScreen mainScreen].bounds.size.width)
//
///** 相对5.5寸屏幕高的比例进行屏幕适配 */
//#define SKRealHeight6P(value)     (long)((value)/736.0f * SKRealHeight)
//
//
///** 字体适配 */
//#define KFontSize(size)          (long)((SCREEN_WIDTH / 375.0f) > 1 ? size * 1.075 : size)



//判断iPhone4系列
#define iPhone4 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 960), [[UIScreen mainScreen] currentMode].size) && !IS_IPAD : NO)
//判断iPhone5系列
#define iPhone5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) && !IS_IPAD : NO)
//判断iPhone6 6s 7系列
#define iPhone6 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(750, 1334), [[UIScreen mainScreen] currentMode].size) && !IS_IPAD : NO)
//判断iPhone6p 6sp 7p系列
#define iPhone6Plus ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1242, 2208), [[UIScreen mainScreen] currentMode].size) && !IS_IPAD : NO)
//判断iPhoneX，Xs（iPhoneX，iPhoneXs）
#define IS_IPHONE_X ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1125, 2436), [[UIScreen mainScreen] currentMode].size) && !IS_IPAD : NO)
//判断iPhoneXr
#define IS_IPHONE_Xr ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(828, 1792), [[UIScreen mainScreen] currentMode].size) && !IS_IPAD : NO)
//判断iPhoneXsMax
#define IS_IPHONE_Xs_Max ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1242, 2688), [[UIScreen mainScreen] currentMode].size)&& !IS_IPAD : NO)

//判断iPhoneX所有系列
#define IS_IPhoneX_All (IS_IPHONE_X || IS_IPHONE_Xr || IS_IPHONE_Xs_Max)
//#define IS_IPhoneX_All ([UIScreen mainScreen].bounds.size.height == 812 || [UIScreen mainScreen].bounds.size.height == 896)
//判断是否为 iPhoneXS  Max，iPhoneXS，iPhoneXR，iPhoneX

#define IsiPhoneX ((int)((SCREEN_HEIGHTL/SCREEN_WIDTHL)*100) == 216)?YES:NO

// 状态栏高度
#define SKStatusBar_Height [[UIApplication sharedApplication] statusBarFrame].size.height
// 顶部导航栏高度
#define SKNavBar_Height 44.0f
// 顶部安全距离
#define SKTopBar_Height (SKStatusBar_Height + SKNavBar_Height)

// Tabbar高度
#define SKTabbarHeight           49.f
// 底部安全距离
#define SKBottomSafe_Height (IS_IPhoneX_All? 34.0f:0.0f)

#define SKTabBar_Height (IS_IPhoneX_All ? (SKTabbarHeight + SKBottomSafe_Height):SKTabbarHeight)


// 去除上下导航栏剩余中间视图高度
#define ContentHeight           (SCREENH_HEIGHT - SKTopBar_Height - SKTabBar_Height)







/**
 *  获取通知中心
 */
#pragma mark --- 获取通知中心




//获取通知中心
#define SKNotificationCenter [NSNotificationCenter defaultCenter]

//快速发通知
#define SKPost_Notify(_notificationName, _obj, _userInfoDictionary) [[NSNotificationCenter defaultCenter] postNotificationName: _notificationName object: _obj userInfo: _userInfoDictionary];

//添加观察者
#define SKAdd_Observer(_notificationName, _observer, _observerSelector, _obj) [[NSNotificationCenter defaultCenter] addObserver:_observer selector:@selector(_observerSelector) name:_notificationName object: _obj];

//移除观察者
#define SKRemove_Observer(_observer) [[NSNotificationCenter defaultCenter] removeObserver: _observer];



/**
 *  颜色
 */
#pragma mark --- 颜色

#define SKRandomColor [UIColor colorWithRed:arc4random_uniform(256)/255.0 green:arc4random_uniform(256)/255.0 blue:arc4random_uniform(256)/255.0 alpha:1.0]

#define SKColorWithHex(rgbValue)  [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16)) / 255.0 green:((float)((rgbValue & 0xFF00) >> 8)) / 255.0 blue:((float)(rgbValue & 0xFF)) / 255.0 alpha:1.0]
#define SKRGBColor(r, g, b) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1.0]
#define SKRGBAColor(r, g, b, a) [UIColor colorWithRed:(r)/255.0 green:(r)/255.0 blue:(r)/255.0 alpha:a]
// clear背景颜色
#define SKClearColor [UIColor clearColor]



/**
 *  字体
 */
#pragma mark --- 字体

#define SKFONT_SIZE(f)            [UIFont systemFontOfSize:(f)]
#define SKFONT_BOLD_SIZE(f)       [UIFont boldSystemFontOfSize:(f)]
#define SKFONT_ITALIC_SIZE(f)     [UIFont italicSystemFontOfSize:(f)]

#define SKFONT_Medium(f)  [UIFont fontWithName:@"PingFangSC-Medium" size:f]
#define SKFONT_Semibold(f)  [UIFont fontWithName:@"PingFangSC-Semibold" size:f]


/**
 *  自定义高效率的 NSLog
 */
#pragma mark --- 自定义高效率的 NSLog
//
//#define SKLog(format, ...) do {            \
//fprintf(stderr, "<%s : %d> %s\n",           \
//[[[NSString stringWithUTF8String:__FILE__] lastPathComponent] UTF8String], \
//__LINE__, __func__);              \
//(NSLog)((format), ##__VA_ARGS__);           \
//fprintf(stderr, "-------\n");            \
//} while (0)

#define SKLog(...) NSLog(@"<类：%s----行：%d> \n 方法：%s\n 输出：%@\n\n",[[[NSString stringWithUTF8String:__FILE__] lastPathComponent] UTF8String],__LINE__,__func__,[NSString stringWithFormat:__VA_ARGS__])

//#ifdef DEBUG
//#define SKLog(...) NSLog(@"%s 第%d行 \n %@\n\n",__func__,__LINE__,[NSString stringWithFormat:__VA_ARGS__])
//#else
//#define SKLog(...)
//
//#endif



/**
 *  设置 view 圆角和边框
 */
#pragma mark --- 设置 view 圆角和边框

#define LRViewBorderRadius(View, Radius, Width, Color)\
\
[View.layer setCornerRadius:(Radius)];\
[View.layer setMasksToBounds:YES];\
[View.layer setBorderWidth:(Width)];\
[View.layer setBorderColor:[Color CGColor]]

/**
 *  由角度转换弧度 由弧度转换角度
 */
#pragma mark --- 由角度转换弧度 由弧度转换角度

#define SKDegreesToRadian(x) (M_PI * (x) / 180.0)
#define SKRadianToDegrees(radian) (radian*180.0)/(M_PI)




/**
 *  数据存储 数据存储 沙盒目录文件
 */
#pragma mark --- 数据存储 沙盒目录文件
//获取temp
#define SKPathTemp NSTemporaryDirectory()

//获取沙盒 Document
#define SKPathDocument [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject]

//获取沙盒 Cache
#define SKPathCache [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) firstObject]

#define SKUserDefaults       [NSUserDefaults standardUserDefaults]

/**
 *  UserDefaults保存信息
 *
 *  @param _value value
 *  @param _key   key
 */
#define SKUserUserDefaults_Save(_value,_key)  [[NSUserDefaults standardUserDefaults] setObject:[(NSDictionary *)_value deleteNull] forKey:_key]

/**
 *  UserDefaults获取信息
 *
 *  @param _key key
 *
 *  @return value
 */
#define SKUserUserDefaults_Get(_key) [[NSUserDefaults standardUserDefaults] objectForKey:_key]

/**
 *  UserDefaults删除信息
 *
 *  @param _key key
 *
 *  @return value
 */
#define SKUserUserDefaults_Remove(_key) [[NSUserDefaults standardUserDefaults] removeObjectForKey:_key]


/**
 *  GCD 的宏定义
 */
#pragma mark --- GCD 的宏定义 ---需要自己加上^{}

//GCD - 一次性执行
#define SKDISPATCH_ONCE_BLOCK(onceBlock) static dispatch_once_t onceToken; dispatch_once(&onceToken, onceBlock);

//GCD - 在Main线程上运行
#define SKDISPATCH_MAIN_THREAD(mainQueueBlock) dispatch_async(dispatch_get_main_queue(), mainQueueBlock);

//GCD - 开启异步线程
#define SKDISPATCH_GLOBAL_QUEUE_DEFAULT(globalQueueBlock) dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), globalQueueBlocl);



/**
 *  数据验证
 */
#pragma mark --- 数据验证 是否为空

#define SKStringIsEmpty(str)     ([str isKindOfClass:[NSNull class]] || str == nil || [str length] < 1 ? YES : NO )
#define SKArrayIsEmpty(array)    (array == nil || [array isKindOfClass:[NSNull class]] || array.count == 0)
#define SKDictIsEmpty(dic)       (dic == nil || [dic isKindOfClass:[NSNull class]] || dic.allKeys == 0)
#define SKHasString(str,key) ([str rangeOfString:key].location!=NSNotFound)




/**
 *  单例模式
 */
#pragma mark --- 单例模式

#define SingleH(name) +(instancetype)share##name;

#if __has_feature(objc_arc)
//条件满足 ARC
#define SingleM(name) static id _instance;\
+(instancetype)allocWithZone:(struct _NSZone *)zone\
{\
static dispatch_once_t onceToken;\
dispatch_once(&onceToken, ^{\
_instance = [super allocWithZone:zone];\
});\
\
return _instance;\
}\
\
+(instancetype)share##name\
{\
return [[self alloc]init];\
}\
\
-(id)copyWithZone:(NSZone *)zone\
{\
return _instance;\
}\
\
-(id)mutableCopyWithZone:(NSZone *)zone\
{\
return _instance;\
}

#else
//MRC
#define SingleM(name) static id _instance;\
+(instancetype)allocWithZone:(struct _NSZone *)zone\
{\
static dispatch_once_t onceToken;\
dispatch_once(&onceToken, ^{\
_instance = [super allocWithZone:zone];\
});\
\
return _instance;\
}\
\
+(instancetype)share##name\
{\
return [[self alloc]init];\
}\
\
-(id)copyWithZone:(NSZone *)zone\
{\
return _instance;\
}\
\
-(id)mutableCopyWithZone:(NSZone *)zone\
{\
return _instance;\
}\
-(oneway void)release\
{\
}\
\
-(instancetype)retain\
{\
return _instance;\
}\
\
-(NSUInteger)retainCount\
{\
return MAXFLOAT;\
}
#endif


/**
 *  时间
 */
#pragma mark --- 时间

//获取系统时间戳
#define SKCurentTime [NSString stringWithFormat:@"%ld", (long)[[NSDate date] timeIntervalSince1970]]





/**
 *  权限
 */
#pragma mark --- 权限

//获取相机权限状态
#define SKCameraStatus [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo]
#define SKCameraDenied ((CameraStatus == AVAuthorizationStatusRestricted)||(CameraStatus == AVAuthorizationStatusDenied))
#define SKCameraAllowed (!CameraDenyed)

/** 定位权限*/
#define SKLocationStatus [CLLocationManager authorizationStatus];
#define SKLocationAllowed ([CLLocationManager locationServicesEnabled] && !((status == kCLAuthorizationStatusDenied) || (status == kCLAuthorizationStatusRestricted)))
#define SKLocationDenied (!LocationAllowed)

/** 消息推送权限*/
#define SKPushClose (([[UIDevice currentDevice].systemVersion floatValue]>=8.0f)?(UIUserNotificationTypeNone == [[UIApplication sharedApplication] currentUserNotificationSettings].types):(UIRemoteNotificationTypeNone == [[UIApplication sharedApplication] enabledRemoteNotificationTypes]))
#define SKPushOpen (!PushClose)

/**
 *  本地文件加载
 */
#pragma mark --- 本地文件加载


#define LoadImage(file,type) [UIImage imageWithContentsOfFile:[[NSBundle mainBundle]pathForResource:file ofType:type]]
#define LoadArray(file,type) [NSArray arrayWithContentsOfFile:[[NSBundle mainBundle]pathForResource:file ofType:type]]
#define  LoadDict(file,type) [NSDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle]pathForResource:file ofType:type]]

/**
 *  定义UIImage对象
 */
#pragma mark --- 定义UIImage对象

#define SKIMAGE_NAMED(name) [UIImage imageNamed:name]
#define SKURLTOSTRING(str)  [NSURL URLWithString:str]

// 过期提醒



#define PPDeprecated(instead) NS_DEPRECATED(2_0, 2_0, 2_0, 2_0, instead)


/**
 *  弱引用/强引用
 */
#pragma mark --- 弱引用/强引用
#define SKWeakSelf __weak typeof(self) weakSelf = self


#define SKWeakObject(type)  __weak typeof(type) weak##type = type;
#define SKStrongObject(type)  __strong typeof(type) type = weak##type;

#define SKWeakObj(o) autoreleasepool{} __weak typeof(o) o##Weak = o;

#define SKStrongObj(o) autoreleasepool{} __strong typeof(o) o = o##Weak;


/**
 *  安全判断
 */
#pragma mark --- 安全判断
#define SafeString(string) !IsStrEmpty((string))?(string):@""
#define SafeArray(id) ([id isKindOfClass:[NSArray class]] ? ((NSArray *)id) : [NSArray array])
//字符串是否为空
#define IsStrEmpty(_ref)    (((_ref) == nil) || ([(_ref) isEqual:[NSNull null]]) ||([(_ref) isEqualToString:@""]))
//数组是否为空
#define IsArrEmpty(_ref)    (((_ref) == nil) || ([(_ref) isEqual:[NSNull null]]) ||([(_ref) count] == 0))
